#include "tmusic.h"

TMusic::TMusic()
{
    music= NULL;
    FileName = "";

}

TMusic::TMusic(std::string filename)
{
    FileName = filename;
    music = Mix_LoadMUS(FileName.c_str());
    if ( music == NULL)
        fprintf(stderr,"Error Cargando el fichero de audio : %s",FileName.c_str());
}

TMusic::~TMusic()
{
    if(music!=NULL)
    {
        Mix_HaltMusic();
        Mix_FreeMusic(music);
        music = NULL;
    }
}

int
TMusic::play()
{
    int i = 0;
    if ( state != true )
    {
        state = true;
        i = Mix_PlayMusic(music, -1);
    }
    return i ;
}

void
TMusic::stop()
{
    if ( state == true)
    {
        state = false;
        Mix_HaltMusic();
    }
}

void
TMusic::pause()
{
    if ( state == true)
    {
        Mix_PauseMusic();
        state = false;
    }
}

void
TMusic::resume()
{
    if ( state ==false)
    {
        Mix_ResumeMusic();
        state = true;
    }
}
